#include <bits/stdc++.h>
using namespace std;
const int N = 30010, M = 30;
int n, m;
int f[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int v, p, w;
    cin >> v >> p;
    w = v * p;
    for (int j = n; j >= v; --j) {
      f[j] = max(f[j], f[j - v] + w);
    }
  }
  cout << f[n] << endl;
}
